home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utildsk / mcdplayr.lha / MCDPlayer2 / Source / Titlelist.c < prev    next >
C/C++ Source or Header  |  1996-05-17  |  10KB  |  317 lines

  1. #include <intuition/intuition.h>
  2. #include <intuition/gadgetclass.h>
  3. #include <libraries/gadtools.h>
  4. #include <graphics/displayinfo.h>
  5. #include <graphics/gfxbase.h>
  6. #include <clib/gadtools_protos.h>
  7. #include <string.h>
  8. #include "mcdplayer.h"
  9.  
  10. #define GD_ListInt                             0
  11. #define GD_ListTitel                           1
  12. #define GD_ListAktTitel                        2
  13. #define GD_ListTitelliste                      3
  14. #define GD_ListSave                            4
  15. #define GD_ListAbbruch                         5
  16. #define GD_ListBenutzen                        6
  17.  
  18. extern struct MsgPort     *TimerMP;
  19.  
  20. struct Window        *ListWnd = NULL;
  21. struct Gadget        *ListGList = NULL;
  22. struct Gadget        *ListGadgets[7];
  23. WORD                  ListLeft;
  24. WORD                  ListTop;
  25. UWORD                 ListWidth = 348;
  26. UWORD                 ListHeight = 174;
  27. UBYTE                *ListWdt = (UBYTE *)"Title List";
  28.  
  29. struct List           TitList;
  30. struct Node           TitNode[100];
  31. char                 *Titles;
  32.  
  33. void InitTitleList( void )
  34.     {
  35.     int i;
  36.  
  37.     if (Titles = AllocMem( 10000, MEMF_ANY|MEMF_CLEAR ))
  38.         {
  39.         NewList( &TitList );
  40.         for( i=0; i<TOC_NumTracks; i++ )
  41.             {
  42.             TitNode[i].ln_Name = &(Titles[i*100]);
  43.             strcpy( &(Titles[i*100]), TOC_Title[i] );
  44.             AddTail( &TitList, &TitNode[i] );
  45.             };
  46.         }
  47.     }
  48.  
  49. void ExitTitleList( int Action ) /* 0=Exit, 1=Use, 2=Save */
  50.     {
  51.     struct StringInfo *sti;
  52.     char *a;
  53.     char Buffer[256];
  54.     int i;
  55.     BPTR FH;
  56.  
  57.     if (Action!=0)
  58.         {
  59.         a = TOC_TitleStrs;
  60.  
  61.         sti = ListGadgets[GD_ListInt]->SpecialInfo;
  62.         strcpy( a, sti->Buffer );
  63.         TOC_CDInterpret = a;
  64.         a += strlen( a )+1;
  65.  
  66.         sti = ListGadgets[GD_ListTitel]->SpecialInfo;
  67.         strcpy( a, sti->Buffer );
  68.         TOC_CDTitle = a;
  69.         a += strlen( a )+1;
  70.  
  71.         for( i=0; i<TOC_NumTracks; i++ )
  72.             {
  73.             strcpy( a, &Titles[i*100] );
  74.             TOC_Title[i] = a;
  75.             a += strlen( a )+1;
  76.             }
  77.         };
  78.  
  79.     if (Action==2)
  80.         {
  81.         sprintf( Buffer, SongPath );
  82.         AddPart( Buffer, TOC_CDID, 130 );
  83.  
  84.         if (FH = Open( Buffer, MODE_NEWFILE ))
  85.             {
  86.             FPuts( FH, TOC_CDInterpret );
  87.             FPutC( FH, '\n' );
  88.             FPuts( FH, TOC_CDTitle );
  89.             FPutC( FH, '\n' );
  90.             for( i=0; i<TOC_NumTracks; i++ )
  91.                 {
  92.                 FPuts( FH, TOC_Title[i] );
  93.                 FPutC( FH, '\n' );
  94.                 };
  95.             Close( FH );
  96.             SetComment(Buffer,TOC_CDTitle);
  97.             };
  98.         };
  99.  
  100.     if (Titles) FreeMem( Titles, 10000 );
  101.     }
  102.  
  103. int OpenListWindow( void )
  104.     {
  105.     struct NewGadget     ng;
  106.     struct Gadget       *g;
  107.     UWORD               offx, offy;
  108.  
  109.     if ( ! ( Scr = LockPubScreen( 0 )))
  110.         return( 1L );
  111.  
  112.     PlaceWnd( Scr, ListWidth, ListHeight + offy, &ListLeft, &ListTop, 0 );
  113.  
  114.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  115.         return( 2L );
  116.  
  117.     offx = Scr->WBorLeft;
  118.     offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  119.  
  120.     if ( ! ( g = CreateContext( &ListGList )))
  121.         return( 1L );
  122.  
  123.     ng.ng_LeftEdge        =    offx + 84;
  124.     ng.ng_TopEdge         =    offy + 2;
  125.     ng.ng_Width           =    250;
  126.     ng.ng_Height          =    14;
  127.     ng.ng_GadgetText      =    (UBYTE *)"Identity";
  128.     ng.ng_TextAttr        =    &topaz8;
  129.     ng.ng_GadgetID        =    GD_ListInt;
  130.     ng.ng_Flags           =    PLACETEXT_LEFT;
  131.     ng.ng_VisualInfo      =    VisualInfo;
  132.  
  133.     g = CreateGadget( STRING_KIND, g, &ng, GTST_MaxChars, 100, GTST_String, TOC_CDInterpret, TAG_DONE );
  134.  
  135.     ListGadgets[ 0 ] = g;
  136.  
  137.     ng.ng_TopEdge         =    offy + 17;
  138.     ng.ng_GadgetText      =    (UBYTE *)"CD Title ";
  139.     ng.ng_GadgetID        =    GD_ListTitel;
  140.  
  141.     g = CreateGadget( STRING_KIND, g, &ng, GTST_MaxChars, 100, GTST_String, TOC_CDTitle, TAG_DONE );
  142.  
  143.     ListGadgets[ 1 ] = g;
  144.  
  145.     ng.ng_TopEdge         =    offy + 140;
  146.     ng.ng_GadgetText      =    (UBYTE *)"Title";
  147.     ng.ng_GadgetID        =    GD_ListAktTitel;
  148.  
  149.     g = CreateGadget( STRING_KIND, g, &ng, GTST_MaxChars, 100, TAG_DONE );
  150.  
  151.     ListGadgets[ 2 ] = g;
  152.  
  153.     ng.ng_TopEdge         =    offy + 32;
  154.     ng.ng_Height          =    120;
  155.     ng.ng_GadgetText      =    NULL;
  156.     ng.ng_GadgetID        =    GD_ListTitelliste;
  157.     ng.ng_Flags           =    0;
  158.  
  159.     g = CreateGadget( LISTVIEW_KIND, g, &ng, GTLV_Labels, &TitList, GTLV_ShowSelected, ListGadgets[2], TAG_DONE );
  160.  
  161.     ListGadgets[ 3 ] = g;
  162.  
  163.     ng.ng_LeftEdge        =    offx + 5;
  164.     ng.ng_TopEdge         =    offy + 153;
  165.     ng.ng_Width           =    80;
  166.     ng.ng_Height          =    14;
  167.     ng.ng_GadgetText      =    (UBYTE *)"Save";
  168.     ng.ng_GadgetID        =    GD_ListSave;
  169.     ng.ng_Flags           =    PLACETEXT_IN;
  170.  
  171.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  172.  
  173.     ListGadgets[ 4 ] = g;
  174.  
  175.     ng.ng_LeftEdge        =    offx + 254;
  176.     ng.ng_GadgetText      =    (UBYTE *)"Cancel";
  177.     ng.ng_GadgetID        =    GD_ListAbbruch;
  178.  
  179.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  180.  
  181.     ListGadgets[ 5 ] = g;
  182.  
  183.     ng.ng_LeftEdge        =    offx + 128;
  184.     ng.ng_GadgetText      =    (UBYTE *)"Use";
  185.     ng.ng_GadgetID        =    GD_ListBenutzen;
  186.  
  187.     g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
  188.  
  189.     ListGadgets[ 6 ] = g;
  190.  
  191.     if ( ! g )
  192.         return( 2L );
  193.  
  194.     if ( ! ( ListWnd = OpenWindowTags( NULL,
  195.                     WA_Left,          ListLeft,
  196.                     WA_Top,           ListTop,
  197.                     WA_Width,         ListWidth,
  198.                     WA_Height,        ListHeight + offy,
  199.                     WA_IDCMP,         STRINGIDCMP|LISTVIEWIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  200.                     WA_Flags,         WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  201.                     WA_Gadgets,       ListGList,
  202.                     WA_Title,         ListWdt,
  203.                     WA_PubScreen,     Scr,
  204.                     TAG_DONE )))
  205.         return( 4L );
  206.  
  207.     GT_RefreshWindow( ListWnd, NULL );
  208.     UnlockPubScreen( NULL, Scr );
  209.     Scr = NULL;
  210.  
  211.     return( 0L );
  212. }
  213.  
  214. void CloseListWindow( void )
  215. {
  216.     if ( ListWnd        )
  217.         {
  218.         CloseWindow( ListWnd );
  219.         ListWnd = NULL;
  220.         }
  221.  
  222.     if ( ListGList      )
  223.         {
  224.         FreeGadgets( ListGList );
  225.         ListGList = NULL;
  226.         }
  227.  
  228.     if ( VisualInfo )
  229.         {
  230.         FreeVisualInfo( VisualInfo );
  231.         VisualInfo = NULL;
  232.         }
  233.  
  234.     if ( Scr )
  235.         {
  236.         UnlockPubScreen( NULL, Scr );
  237.         }
  238. }
  239.  
  240. void TitleList( void )
  241.     {
  242. /*    ULONG  GClass;
  243.     USHORT GCode;
  244.     struct Gadget *GList = 0l;
  245.     struct IntuiMessage  *msg;
  246.     struct StringInfo *sti;
  247.     int Exit = 0;
  248.     int AktTitel = -1;
  249.     LONG Sig;
  250. */
  251.     InitTitleList();
  252.     if (OpenListWindow()) {CloseListWindow();ExitTitleList(0);}
  253. }
  254. void Handle_ListInput(void)
  255. {
  256.     ULONG  GClass;
  257.     USHORT GCode;
  258.     struct Gadget *GList = 0l;
  259.     struct IntuiMessage  *msg;
  260.     struct StringInfo *sti;
  261.     static int AktTitel = -1;
  262.                    while (msg = (struct IntuiMessage *) GT_GetIMsg( ListWnd->UserPort ) )
  263.                    {
  264.                    GClass  = msg->Class;
  265.                    GCode   = msg->Code;
  266.                    if (GClass & (GADGETDOWN | GADGETUP | MOUSEMOVE) )
  267.                        GList   = (struct Gadget *) msg->IAddress;
  268.                    GT_ReplyIMsg(msg);
  269.  
  270.                 switch (GClass)
  271.                     {
  272.                     case IDCMP_CLOSEWINDOW:
  273.                         ExitTitleList(0);
  274.                         CloseListWindow();
  275.                         return;
  276.                     case IDCMP_GADGETUP:
  277.                         switch (GList->GadgetID)
  278.                             {
  279.                             case GD_ListAktTitel:
  280.                                 if (AktTitel!=-1)
  281.                                     {
  282.                                     sti = ListGadgets[GD_ListAktTitel]->SpecialInfo;
  283.                                     strcpy( &Titles[AktTitel*100], sti->Buffer );
  284.                                     if (AktTitel<TOC_NumTracks-1) AktTitel++;
  285.                                     GT_SetGadgetAttrs(ListGadgets[GD_ListTitelliste], ListWnd, 0,GTLV_Labels, &TitList, GTLV_Selected, AktTitel, GTLV_MakeVisible, AktTitel-1, TAG_DONE);
  286.                                     ActivateGadget(ListGadgets[GD_ListAktTitel], ListWnd, NULL );
  287.                                     };
  288.                                 break;
  289.                             case GD_ListTitelliste:
  290.                                 AktTitel = GCode;
  291.                                 ActivateGadget(ListGadgets[GD_ListAktTitel], ListWnd, NULL );
  292.                                 break;
  293.                             case GD_ListInt:
  294.                                 ActivateGadget(ListGadgets[GD_ListTitel], ListWnd, NULL );
  295.                                 break;
  296.                             case GD_ListTitel:
  297.                                 ActivateGadget(ListGadgets[GD_ListInt], ListWnd, NULL );
  298.                                 break;
  299.                             case GD_ListSave:
  300.                                 ExitTitleList(2);
  301.                                 CloseListWindow();
  302.                                 return;
  303.                             case GD_ListAbbruch:
  304.                                 ExitTitleList(0);
  305.                                 CloseListWindow();
  306.                                 return;
  307.                             case GD_ListBenutzen:
  308.                                 ExitTitleList(1);
  309.                                 CloseListWindow();
  310.                                 return;
  311.                             };
  312.                         break;
  313.                     };
  314.                 };
  315.             }
  316.  
  317.